package com.demo1.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
 * Web项目配置类
 */
@Configuration
@EnableWebMvc
public class WebAppConfigurer implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "HEAD", "POST", "PUT",
                        "DELETE","OPTIONS")
                .maxAge(3600);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/image/pet/**").addResourceLocations("file:E:\\Images\\petImages\\");
        registry.addResourceHandler("/image/order/**").addResourceLocations("file:E:\\Images\\orderImages\\");
        registry.addResourceHandler("/image/petHealth/**").addResourceLocations("file:E:\\Images\\petHealth\\");
        registry.addResourceHandler("/image/productParaImgs/**").addResourceLocations("file:D:\\java1234-mall\\productParaImgs\\");
    }
}
